<?php
/**
 * Класс для обработки заявки на участие в тендере
 *
 * @author kingop
 */
class FormProcessor_RequestEdit extends FormProcessor {
    
    protected $db = null;
    public $request = null;
    
    public function __construct($db,$id) {
        parent::__construct();
        
        $this->db = $db;
        $this->request = new DatabaseObject_Requests($this->db);
         $this->request->load($id);
        $this->firm_name = $this->request->firm_name;
        $this->firm_info = $this->request->firm_info;
        $this->firm_zavod = $this->request->firm_zavod;
        $this->firm_manager_fio = $this->request->firm_manager_fio;
        $this->firm_face_info = $this->request->firm_face_info;
        $this->firm_ext_info = $this->request->firm_ext_info;
        $this->gosreg_copy = $this->request->gosreg_copy;
        $this->egrpou = $this->request->egrpou;
        $this->nds = $this->request->nds;
        $this->agree_face = $this->request->agree_face;
        $this->ustav_copy = $this->request->ustav_copy;
        $this->allow_docs = $this->request->allow_docs;
        $this->pass_page = $this->request->pass_page;
        $this->doc_director = $this->request->doc_director;
        $this->bank_info = $this->request->bank_info;
        $this->gni = $this->request->gni;
        $this->suggest = $this->request->suggest;
        $this->people = $this->request->people;
        $this->is_soft = $this->request->is_soft;
        $this->expr = $this->request->expr;
        $this->recomend = $this->request->recomend;
        $this->main_distr = $this->request->main_distr;
        $this->tech = $this->request->tech;
        
        $this->files = $this->request->files;
    }
    
    public function process(Zend_Controller_Request_Abstract $request) {
        // сохранить все это - ппц трешак, но мы это сделаем :)
        
        $this->request->idUser = $request->getPost('idUser');
        $this->request->idTender = $request->getPost('idTender');
        
        $this->firm_name = trim($request->getPost('firm_name'));
        if (strlen($this->firm_name) == 0)
            $this->addError('firm_name', 'Поле должно быть заполнено');
        else $this->request->firm_name = $this->firm_name;
        
        $this->firm_info = trim($request->getPost('firm_info'));
        if (strlen($this->firm_info) == 0)
            $this->addError('firm_info', 'Поле должно быть заполнено');
        else $this->request->firm_info = $this->firm_info;
        
        $this->firm_zavod = trim($request->getPost('firm_zavod'));
        if (strlen($this->firm_zavod) == 0)
            $this->addError('firm_zavod', 'Поле должно быть заполнено');
        else $this->request->firm_zavod = $this->firm_zavod;
        
        $this->firm_manager_fio = trim($request->getPost('firm_manager_fio'));
        if (strlen($this->firm_manager_fio) == 0)
            $this->addError('firm_manager_fio', 'Поле должно быть заполнено');
        else $this->request->firm_manager_fio = $this->firm_manager_fio;
        
        $this->firm_face_info = trim($request->getPost('firm_face_info'));
        if (strlen($this->firm_face_info) == 0)
            $this->addError('firm_face_info', 'Поле должно быть заполнено');
        else $this->request->firm_face_info = $this->firm_face_info;
        
        $this->firm_ext_info = trim($request->getPost('firm_ext_info'));
        if (strlen($this->firm_ext_info) == 0)
            $this->addError('firm_ext_info', 'Поле должно быть заполнено');
        else $this->request->firm_ext_info = $this->firm_ext_info;
        
        if($request->getPost('gosreg_copy')) {
            $this->request->gosreg_copy = 1;
            $this->gosreg_copy = 1;
        }
        else $this->request->gosreg_copy = 0;
        
        if($request->getPost('egrpou')) {
            $this->request->egrpou = 1;
            $this->egrpou = 1;
        }
        else $this->request->egrpou = 0;
        
        if($request->getPost('nds')) {
            $this->request->nds = 1;
            $this->nds = 1;
        }
        else $this->request->nds = 0;
        
        if($request->getPost('agree_face')) {
            $this->request->agree_face = 1;
            $this->agree_face = 1;
        }
        else $this->request->agree_face = 0;
        
        if($request->getPost('ustav_copy')) {
            $this->request->ustav_copy = 1;
            $this->ustav_copy = 1;
        }
        else $this->request->ustav_copy = 0;
        
        if($request->getPost('allow_docs')) {
            $this->request->allow_docs = 1;
            $this->allow_docs = 1;
        }
        else $this->request->allow_docs = 0;
        
        if($request->getPost('pass_page')) {
            $this->request->pass_page = 1;
            $this->pass_page = 1;
        }
        else $this->request->pass_page = 0;
        
        if($request->getPost('doc_director')) {
            $this->request->doc_director = 1;
            $this->doc_director = 1;
        }
        else $this->request->doc_director = 0;
        
        if($request->getPost('bank_info')) {
            $this->request->bank_info = 1;
            $this->bank_info = 1;
        }
        else $this->request->bank_info = 0;
        
        if($request->getPost('gni')) {
            $this->request->gni = 1;
            $this->gni = 1;
        }
        else $this->request->gni = 0;
        
        if($request->getPost('gni')) {
            $this->request->gni = 1;
            $this->gni = 1;
        }
        else $this->request->gni = 0;
        
        if($request->getPost('suggest')) {
            $this->request->suggest = 1;
            $this->suggest = 1;
        }
        else $this->request->suggest = 0;
        
        if($request->getPost('people')) {
            $this->request->people = 1;
            $this->people = 1;
        }
        else $this->request->people = 0;
        
        if($request->getPost('is_soft')) {
            $this->request->is_soft = 1;
            $this->is_soft = 1;
        }
        else $this->request->is_soft = 0;
        
        if($request->getPost('expr')) {
            $this->request->expr = 1;
            $this->expr = 1;
        }
        else $this->request->expr = 0;
        
        if($request->getPost('recomend')) {
            $this->request->recomend = 1;
            $this->recomend = 1;
        }
        else $this->request->recomend = 0;
        
        if($request->getPost('main_distr')) {
            $this->request->main_distr = 1;
            $this->main_distr = 1;
        }
        else $this->request->main_distr = 0;
        
        if($request->getPost('tech')) {
            $this->request->tech = 1;
            $this->tech = 1;
        }
        else $this->request->tech = 0;
        
        $this->request->dtime = date("Y-m-d H:i:s");
        $this->request->isApproved = 0;
        $this->request->isDeleted = 0;
        $this->request->deleteReason = '';
        
        $this->file = $request->getPost('filesrc');
       
        if (count($this->file) == 0 && count($this->files)==0)
            $this->addError('file', 'Загрузите файл');
        else 
        $this->fileupload = $this->file;
        
        if (!$this->_validateOnly && !$this->hasError()) {
            $this->request->save();
            $id = $this->request->getId();
              foreach ($this->fileupload as $val) {
                if (DatabaseObject_RequestFiles::UploadFile($this->db, $id, $val))
                
                   echo 'Yes'; 
                
                echo 'No';
                }
        }
        
        return !$this->hasError();
    }
}

?>